home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / http.thor < prev    next >
Text File  |  1998-05-24  |  9KB  |  315 lines

  1. /*
  2.    $VER http.thor 0.8 (22.2.96)
  3.    by Remco van Hooff
  4.  
  5. !~ "HISTORY"
  6.    0.2 - URL is now shown in the Browser/GetNET requester (only if he parsed
  7.          URL doesn't contain a doublequote).
  8.        - Added Index to locate the presence of the arexx port
  9.          of a browser.
  10.        - Added SCREENTOFRONT and RELOAD for AWeb.
  11.        - Removed loading of rexxsupport.library, it's not needed.
  12.        - Forgot to call the Thor ARexx port before calling REQUESTNOTIFY.
  13.  
  14.    0.3 - Fixed the non working AMosaic part.
  15.        - Added Voyager support.
  16.        - Start browser when needed.
  17.        - Start TCP/IP stack when needed (optionally, AWebII 2.1+ only).
  18.        - Optionally save the url (IBrowse 1.02+ only).
  19.        - Distributed on IRC only.
  20.  
  21.    0.4 - Changed the way the auto url save thingy for IBrowse works.
  22.          It now waits until the title isn't '(Untitled)' or after the
  23.          timeout period has passed.
  24.          Thanks to Shaun Downend for helping to fix this.
  25.  
  26.    0.5 - Forgot to start the TCP/IP stack if a browser wasn't running yet.
  27.        - Changed the requester text when a browser would fain to start.
  28.        - Now Checking for a browser presence before the first requester
  29.          pops up, saving one requester when the browser isn't found.
  30.        - Will ask what to do when the page title returned is 'IBrowse Error',
  31.          'Proxy Message' or '(Untitled)'. (IBrowse only)
  32.  
  33.    0.6 - Added Retry button to the requester that pops up if IBrowse is unable
  34.          grab the page title within the timeout. Retry will grab the current
  35.          tilte and save the url with that title (much like the add button in
  36.          IBrowse itself).
  37.  
  38.    0.7 - Added external config handling stuff.
  39.        - Changed the Voyager ARexx port from MINDWALKER to VOYAGER. This change
  40.          means that only Voyager 2.0+ will be supported
  41.  
  42.    0.8 - Removed old config things.
  43.        - Added option to start cfgHTTP when no config is found.
  44.        - Removed ~ in the check_tcp.
  45. ~!
  46. */
  47.  
  48. /*!~ "Variables" */
  49. cfgpath = 'env:thor/'
  50. cfgfile = 'http.config'
  51. CALL OPEN(tmp, 'env:thor/thorpath')
  52.   thorpath = readln(tmp)
  53. CALL CLOSE(tmp)
  54. /*~!*/
  55.  
  56. /*!~ "Init" */
  57. OPTIONS RESULTS
  58. OPTIONS FAILAT 31
  59. /*TRACE RESULTS*/
  60.  
  61. p=' '||ADDRESS()||' '||SHOW('P',,)
  62. IF POS(' THOR.',p)>0 THEN thorport=WORD(SUBSTR(p,POS(' THOR.',p)+1),1)
  63. ELSE DO
  64.   SAY 'THOR port not found!'
  65.   EXIT 10
  66. END
  67.  
  68. IF ~SHOW('p', 'BBSREAD') THEN DO
  69.   ADDRESS COMMAND
  70.     "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  71.     "WaitForPort BBSREAD"
  72. END
  73.  
  74. IF ~SHOW('L','rexxsupport.library') THEN CALL ADDLIB('rexxsupport.library',0,-30,0)
  75. IF ~SHOW('L','rexxsupport.library') THEN DO
  76.   'REQUESTNOTIFY TEXT "Couldn''t open rexxsupport.library" BT "_Ok"'
  77.   EXIT
  78. END
  79. /*~!*/
  80.  
  81. /*!~ "Main"*/
  82. PARSE ARG url
  83.  
  84. CALL loadprefs
  85. ADDRESS(thorport)
  86. CALL check_browser
  87.  
  88. reqtxt = url'\n\nWhat do you want to do with the URL?\n · Send URL to WWW Browser\n · Save the URL using GetNET'
  89. IF browser_port THEN buttons = '_Browser|_GetNET|_Quit'
  90. ELSE buttons = '_Start Browser|_GetNET|_Quit'
  91.  
  92. 'REQUESTNOTIFY TEXT "'reqtxt'" BT "'buttons'"'
  93. answer = RESULT
  94.  
  95. IF browser_port THEN DO
  96.   SELECT
  97.     WHEN answer = 1 THEN DO
  98.       CALL check_tcp
  99.       CALL send_browser
  100.     END
  101.     WHEN answer = 2 THEN CALL send_getnet
  102.     OTHERWISE EXIT
  103.   END
  104. END
  105.  
  106. ELSE DO
  107.   SELECT
  108.     WHEN answer = 1 THEN DO
  109.       CALL check_tcp
  110.       CALL start_browser
  111.     END
  112.     WHEN answer = 2 THEN CALL send_getnet
  113.     OTHERWISE EXIT
  114.   END
  115. END
  116.  
  117. EXIT
  118. /*~!*/
  119.  
  120. /*!~ "LoadPrefs" */
  121. loadprefs:
  122.   IF ~EXISTS(cfgpath||cfgfile) THEN DO
  123.     Address(thorport)
  124.     'Requestnotify TEXT "Could not find the configuration file.\nRun CfgHTTP to create one or quit." BT "_CfgHTTP|_Quit"'
  125.     IF RC = 0 THEN DO
  126.       IF RESULT = 0 THEN EXIT
  127.       IF RESULT = 1 THEN ADDRESS COMMAND 'rx' thorpath'rexx/cfghttp.thor'
  128.     END
  129.     EXIT
  130.   END
  131.   ELSE DO
  132.     CALL OPEN(prf,cfgpath||cfgfile,'R')
  133.       DO UNTIL EOF(prf)
  134.         line = READLN(prf)
  135.         SELECT
  136.           WHEN UPPER(WORD(line,1)) = 'GETNET' THEN DO
  137.             getnet = SUBWORD(line,2)
  138.           END
  139.           WHEN UPPER(WORD(line,1)) = 'BROWSER' THEN DO
  140.             browser = WORD(line,2)
  141.           END
  142.           WHEN UPPER(WORD(line,1)) = 'BROWSEREXE' THEN DO
  143.             browserexe = SUBWORD(line,2)
  144.           END
  145.           WHEN UPPER(WORD(line,1)) = 'SAVE_URL' THEN DO
  146.             save_url = WORD(line,2)
  147.           END
  148.           WHEN UPPER(WORD(line,1)) = 'SAVEDELAY' THEN DO
  149.             savedelay = WORD(line,2)
  150.           END
  151.           WHEN UPPER(WORD(line,1)) = 'AWEB_TCP' THEN DO
  152.             aweb_tcp = WORD(line,2)
  153.           END
  154.           WHEN UPPER(WORD(line,1)) = 'TCP_IP' THEN DO
  155.             tcp_ip = SUBWORD(line,2)
  156.           END
  157.           OTHERWISE NOP
  158.         END
  159.       END
  160.     CALL CLOSE(prf)
  161.     CALL checkprefs
  162.   END
  163. RETURN
  164. /*~!*/
  165.  
  166. /*!~ "CheckPrefs" */
  167. checkprefs:
  168.   IF getnet = ''                 THEN CALL prefserror('GETNET')
  169.   IF ~DATATYPE(browser, 'NUM')   THEN CALL prefserror('BROWSER')
  170.   IF browserexe = ''             THEN CALL prefserror('BROWSEREXE')
  171.   IF ~DATATYPE(save_url, 'BIN')  THEN CALL prefserror('SAVE_URL')
  172.   IF ~DATATYPE(savedelay, 'NUM') THEN CALL prefserror('SAVEDELAY')
  173.   IF ~DATATYPE(aweb_tcp, 'BIN')  THEN CALL prefserror('AWEB_TCP')
  174.   IF tcp_ip = '' THEN tcp_ip = 'RequestChoice >NIL: TITLE="HTTP ERROR" BODY="No TCP/IP stack to run. Use CfgHTTP to edit." GADGETS="OK" Pubscreen=Thor.1'
  175. RETURN
  176. /*~!*/
  177.  
  178. /*!~ "PrefsError" */
  179. prefserror:
  180.   prferr = ARG(1)
  181.   ADDRESS(thorport)
  182.   'REQUESTNOTIFY TEXT "The config file is not in the\ncorrect format. An error occured at\nor before 'prferr'.\nPlease run CfgHTTP to correct this.\n\nIf the problem remains, contact\nthe author at rvhooff@caiw.nl" BT "_OK"'
  183.   EXIT
  184. RETURN
  185. /*~!*/
  186.  
  187. /*!~ "Check for Browser" */
  188. check_browser:
  189.   SELECT
  190.     WHEN INDEX(SHOW('P'),'IBROWSE') > 0 THEN DO
  191.       browser_port = 1
  192.       RETURN
  193.     END
  194.     WHEN INDEX(SHOW('P'),'AWEB.1') > 0 THEN DO
  195.       browser_port = 1
  196.       RETURN
  197.     END
  198.     WHEN INDEX(SHOW('P'),'AMOSAIC.1') > 0 THEN DO
  199.       browser_port = 1
  200.       RETURN
  201.     END
  202.     WHEN INDEX(SHOW('P'),'VOYAGER') > 0 THEN DO
  203.       browser_port = 1
  204.       RETURN
  205.     END
  206.     OTHERWISE browser_port = 0
  207.   END
  208. RETURN
  209. /*~!*/
  210.  
  211. /*!~ "Check for TCP/IP"*/
  212. check_tcp:
  213.   IF (aweb_tcp & browser = 2) THEN RETURN
  214.   ELSE DO
  215.     IF ~SHOWLIST('L','bsdsocket.library') THEN DO
  216.       ADDRESS COMMAND tcp_ip
  217.       IF SHOWLIST('L','bsdsocket.library') THEN CALL send_browser
  218.       ELSE DO
  219.         'REQUESTNOTIFY TEXT "No TCP/IP stack found.n\nCan''t connect to the URL." BT "_OK"'
  220.       END
  221.     END
  222.   END
  223. RETURN
  224. /*~!*/
  225.  
  226. /*!~ "Send to Browser" */
  227. send_browser:
  228.   SELECT
  229.     WHEN INDEX(SHOW('P'),'IBROWSE') > 0 THEN DO
  230.       ADDRESS 'IBROWSE'
  231.       'QUERY TITLE'
  232.       oldpagetitle = RESULT
  233.       'GOTOURL' url
  234.       IF save_url THEN DO
  235.         timeout = TIME('S')
  236.         DO FOREVER
  237.           'QUERY TITLE'
  238.           pagetitle = RESULT
  239.           IF (pagetitle ~= '(Untitled)' & oldpagetitle ~= pagetitle) THEN LEAVE
  240.           IF TIME('S') >= timeout + savedelay THEN LEAVE
  241.         END
  242.         IF (pagetitle = 'IBrowse Error' | pagetitle = 'Proxy Message' | pagetitle = '(Untitled)') THEN DO
  243.           ADDRESS(thorport)
  244.           'THORTOFRONT'
  245.           reqbody = 'Unable to find the page title for:\n\n'url'\n\nYou have 4 options:\n · Change the title\n · Retry (grab the title now)\n · Clear it (save but no title)\n · Discard the URL and not save it'
  246.           'REQUESTSTRING TITLE "Title error" BODY "'reqbody'" BT "_OK|_Retry|_Clear|_Discard" ID "'pagetitle'"'
  247.           IF (RC = 30) THEN DO
  248.             'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  249.             EXIT
  250.           END
  251.           IF RC = 5 THEN EXIT
  252.           IF RC = 0 THEN DO
  253.             IF THORRC = 1 THEN pagetitle = RESULT
  254.             IF THORRC = 2 THEN DO
  255.                ADDRESS 'IBROWSE'
  256.                'QUERY TITLE'
  257.                pagetitle = RESULT
  258.             END
  259.             IF THORRC = 3 THEN pagetitle = ''
  260.           END
  261.         ADDRESS 'IBROWSE'
  262.         END
  263.         'ADDHOTLIST TITLE "'pagetitle'" LOCATION' url
  264.       END
  265.       EXIT
  266.     END
  267.     WHEN INDEX(SHOW('P'),'AWEB.1') > 0 THEN DO
  268.       ADDRESS 'AWEB.1'
  269.       'OPEN URL' url 'RELOAD'
  270.       'SCREENTOFRONT'
  271.       EXIT
  272.     END
  273.     WHEN INDEX(SHOW('P'),'AMOSAIC.1') > 0 THEN DO
  274.       ADDRESS 'AMOSAIC.1'
  275.       'JUMP URL' url
  276.       EXIT
  277.     END
  278.     WHEN INDEX(SHOW('P'),'VOYAGER') > 0 THEN DO
  279.       ADDRESS 'VOYAGER'
  280.       'OPENURL URL' url
  281.       EXIT
  282.     END
  283.     OTHERWISE DO
  284.       'REQUESTNOTIFY TEXT "Browser not found, either your path\nto the browser is incorrect or there\nis another reason your browser is\nunable to start." BT "_OK"'
  285.       EXIT
  286.     END
  287.   END
  288. RETURN
  289. /*~!*/
  290.  
  291. /*!~ "Start Browser"*/
  292. start_browser:
  293.   ADDRESS COMMAND 'run >nil:' browserexe
  294.   SELECT
  295.     WHEN browser = 1 THEN port = 'IBROWSE'
  296.     WHEN browser = 2 THEN port = 'AWEB.1'
  297.     WHEN browser = 3 THEN port = 'AMOSAIC.1'
  298.     WHEN browser = 4 THEN port = 'MINDWALKER'
  299.     OTHERWISE DO
  300.       'REQUESTNOTIFY TEXT "No running browser found." BT "_OK"'
  301.       EXIT
  302.     END
  303.   END
  304.   ADDRESS COMMAND 'waitforport' port
  305.   CALL send_browser
  306. RETURN
  307. /*~!*/
  308.  
  309. /*!~ "Send to GetNET" */
  310. send_getnet:
  311.   ADDRESS COMMAND 'rx' getnet 'URL' url
  312. RETURN
  313. /*~!*/
  314.  
  315.